package com.gensdai.leliang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gensdai.leliang.R;
import com.gensdai.leliang.entity.Call;
import com.gensdai.leliang.entity.User;

import java.util.List;

/**
 * Created by Administrator on 2017/6/2.
 */

public class system_list_adapter extends BaseAdapter {

    Context mContext;
    List<Call> list;
    Honder honder;
    deleteItem DI;

    public system_list_adapter(Context context, List<Call> list, deleteItem di) {
        mContext = context;
        this.list = list;
        DI = di;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            honder = new Honder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.sys_tem_list, null);
            honder.time = (TextView) convertView.findViewById(R.id.time);
            honder.delete = (TextView) convertView.findViewById(R.id.delete);
            honder.data = (TextView) convertView.findViewById(R.id.data);
            honder.dian = (ImageView) convertView.findViewById(R.id.dian);
            honder.title = (TextView) convertView.findViewById(R.id.title);

            convertView.setTag(honder);
        } else {
            honder = (Honder) convertView.getTag();
        }
        honder.time.setText(list.get(position).getTime());
        honder.data.setText(list.get(position).getDetails());
        honder.title.setText(list.get(position).getTitle());
        if (list.get(position).getCall_state().equals("0")) {
            honder.dian.setVisibility(View.VISIBLE);
        } else {
            honder.dian.setVisibility(View.GONE);
        }

        honder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (DI != null) {
                    DI.delete(position);
                }
            }
        });

        return convertView;
    }

    public interface deleteItem {
        void delete(int position);
    }

    class Honder {

        TextView time;
        TextView delete;
        TextView data;
        ImageView dian;
        TextView title;
    }

}
